package sendcloud

import (
	"net/smtp"
)

type Auth struct {
	user     string
	password string
}

func NewAuth(user, password string) smtp.Auth {
	return &Auth{user: user, password: password}
}

func (self *Auth) Start(server *smtp.ServerInfo) (string, []byte, error) {
	return "LOGIN", []byte(self.user), nil
}

func (self *Auth) Next(fromServer []byte, more bool) ([]byte, error) {
	if more {
		switch string(fromServer) {
		case "Username:":
			return []byte(self.user), nil
		case "Password:":
			return []byte(self.password), nil
		}
	}
	return nil, nil
}
